package cn.lingyangwl.agile.tenant;

import cn.lingyangwl.agile.model.module.tenant.TenantContext;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author shenguangyang
 */
@Slf4j
@Component
@Aspect
public class SpringRabbitMqListenerAspect {

    @Around("@annotation(org.springframework.amqp.rabbit.annotation.RabbitListener) " +
            "|| @annotation(org.springframework.amqp.rabbit.annotation.RabbitHandler)")
    public Object handle(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        try {
            return proceedingJoinPoint.proceed();
        } finally {
            log.debug("mq-清除租户上下文");
            TenantContext.clear();
        }
    }
}
